# -*- coding: utf-8 -*-
############################################################################
from chee.shortcuts import *
from chee.models import User_Info
############################################################################
class Resource_Helper(AuthHandler):
    rule = Rule('/res/')
    def get(self):
        # two parameters, type & id & prefix
        type = self.request.args.get('type','').strip()
        sub = self.request.args.get('sub','').strip()
        id = self.request.args.get('id','').strip()
        prefix = self.request.args.get('prefix','').strip()
        if not type: raise NotFound
        
        if type == 'test': return redirect('/static/images/user_l.gif')
        elif type == 'farm': return self.getFarmRes(sub, id, prefix)
        elif type == 'battle': return self.getBattleRes(sub, id, prefix)
        elif type == 'plant': return self.getPlantRes(sub, id, prefix)
        elif type == 'beast': return self.getBeastRes(sub, id, prefix)
        raise NotFound
    def getFarmRes(self,sub,id,prefix):
        return redirect('/static/data/farm/%s/%s_%s.fla' % (sub,id,prefix))
    def getBattleRes(self,sub,id,prefix):
        return redirect('/static/data/battle/%s/%s_%s.fla' % (sub,id,prefix))
    def getPlantRes(self,sub,id,prefix):
        return redirect('/static/data/plant/%s/%s_%s.fla' % (sub,id,prefix))
    def getBeastRes(self,sub,id,prefix):
        return redirect('/static/data/beast/%s/%s_%s.fla' % (sub,id,prefix))
